package czk.concrent.enjoyModelWithNotLock.phaser;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Phaser;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/9/19 16:53
 */
public class PhaserDemo {
    public static void main(String[] args) {
        Phaser phaser=new Phaser(5);
        Runnable r=()->{
            System.out.println("phase-0");
            phaser.arriveAndAwaitAdvance();
            // 恢复
            System.out.println("phase-1");
            phaser.arriveAndAwaitAdvance();
            System.out.println("phase-2");
            phaser.arriveAndDeregister();
        };
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 5; i++) {
            executorService.submit(r);
        }
    }
}
